/*****************************************************************************
 *   Copyright 2005 Tim A Wang
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 ****************************************************************************/
package com.jb.web.bean.custom.renderer;

import com.jb.web.bean.Link;
import com.jb.web.context.WebContext;
import com.jb.web.renderer.LinkRenderer;


public class FileLinkRenderer extends LinkRenderer {
    protected String renderALink(WebContext pCtx, Link hItem, String value) {
        // String src = "resources/images/ext/jpg.gif";
        String urlStr = getURL(pCtx, hItem);
        String url = urlStr.toLowerCase();
        String ext = url.substring(url.lastIndexOf(".") + 1);

        if (ext != null) {
            url = "resources/images/ext/" + ext + ".gif";
        } else {
            url = "resources/images/ext/file.gif";
        }

        StringBuffer sb = new StringBuffer("<a ");

        String desc = (String) evaluate(pCtx, hItem, hItem.getTitle());
        sb.append(getEditScript(pCtx, hItem)).append(addTagProperty("style", hItem.getStyle(pCtx), null))
          .append(addTagProperty("class", hItem.getStyleClass(), null)).append(addTagProperty("href", urlStr, null))
          .append(addTagProperty("title", desc, null)).append(" ><img ").append(addTagProperty("src", url, null))
          .append(" >").append("</img>").append("</a> ");

        return sb.toString();
    }
}
